package demo2;

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student = new Student();
        student.name = "zhangsan";
        student.money.m = 199;
//        Student student1 = (Student) student.clone();
//        System.out.println(student.name + " "  + student.money.m);
//        System.out.println(student1.name + " " + student1.money.m);
        Student student1 = (Student) student.clone();
        student.money.m = 108;
        System.out.println(student.name + " "  + student.money.m);
        System.out.println(student1.name + " " + student1.money.m);
    }
}





 class Student implements Cloneable {
    public String name;
    public Money money = new Money();


    @Override
    protected Object clone() throws CloneNotSupportedException {
       // return super.clone();
        Student student1 = (Student) super.clone();
        student1.money = (Money) this.money.clone();
        return student1;

    }
}




 class Money implements Cloneable{
    public int m = 100;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}